package com.mz;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

/**
 * Created by germmy on 17/9/30.
 */
public class PropertiesClient {



//    //读取properties的全部信息
//    public  static  void readProperties(String filePath) {
//        Properties props = new Properties();
//        try {
//            InputStream in = new BufferedInputStream(new FileInputStream(filePath));
//            props.load(in);
//        } catch (Exception e) {
//            throw  new RuntimeException("配置文件找不到，请检查配置外化文件");
//        }
//        Enumeration en = props.propertyNames();
//        while (en.hasMoreElements()) {
//            String key = (String) en.nextElement();
//            String Property = props.getProperty (key);
//            System.out.println(key+Property);
//        }
//    }



    //根据key读取value
    public static String readValue(String filePath,String key) {
        Properties props = new Properties();
        try {
            InputStream in = new BufferedInputStream (new FileInputStream(filePath));
            props.load(in);
            String value = props.getProperty (key);
            return value;
        } catch (Exception e) {
            throw  new RuntimeException("配置文件找不到，Linux在/Java_Files/config/config.properties，Windows在D:/Java_Files/config/config.properties");
        }
    }


}
